package miscs

import (
	"context"
	"sync"
)

// AdvancedContext 自定义Context
type AdvancedContext struct {
	context.Context
	Wait sync.WaitGroup

	cancel context.CancelCauseFunc
}

func NewCancelAdvancedContext(parent context.Context) *AdvancedContext {
	ctx, cancel := context.WithCancelCause(parent)

	return &AdvancedContext{
		Context: ctx,
		cancel:  cancel,
	}
}

func (c *AdvancedContext) Cancel(err error) {
	c.cancel(err)
}
